<!DOCTYPE html>
<html lang="en">

<head>
  <!-- Use correct character set. -->
  <meta charset="utf-8" />
  <!-- Tell IE to use the latest, best version. -->
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <!-- Make the application on mobile take up the full browser screen and disable user scaling. -->
  <meta name="viewport"
    content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
  <title>Hello World!</title>
  <script src="../Build/Cesium/Cesium.js"></script>
  <style>
    @import url(../Build/Cesium/Widgets/widgets.css);

    html,
    body,
    #cesiumContainer {
      width: 100%;
      height: 100%;
      margin: 0;
      padding: 0;
      overflow: hidden;
    }
  </style>
</head>

<body>
  <div id="credit"></div>
  <div id="cesiumContainer"></div>
  <script>
    // Cesium.Ion.defaultAccessToken = '<YOUR ACCESS TOKEN>'
    var viewer = new Cesium.Viewer("cesiumContainer",
      {
        geocoder: true,             // 1.开启geo搜索框
        homeButton: true,           // 2.Home button
        sceneModePicker: true,      // 3.二三维切换按钮
        baseLayerPicker: true,       // 4.Layer选择
        navigationHelpButton: true, // 5.帮助按钮
        animation: true,            // 6.动画按钮
        //creditContainer: "credit",   // 7. Cesium logo
        timeline: true,             // 8.底部时间线
        fullscreenButton: true      // 9.全屏按钮
      });

    // 
    // 加载3D tileset
    var tileset_url = "";
    // 错误的路径
    // tileset_url = "/Apps/SampleData/Cesium3DTiles/Tilesets/Tileset/";
    // 正确的路径
    tileset_url = "/Apps/SampleData/Cesium3DTiles/Tilesets/Tileset/tileset.json";
    tileset_url = "http://localhost:8080/Apps/SampleData/Cesium3DTiles/Tilesets/Tileset/tileset.json";
    // 跨域问题
    tileset = new Cesium.Cesium3DTileset({ url: tileset_url });
    tileset.readyPromise.then(function (tileset) {
      // 添加tileset到viewer
      viewer.scene.primitives.add(tileset);
      default_HeadingPitchRange = new Cesium.HeadingPitchRange(0.0, -0.5, tileset.boundingSphere.radius * 2.0);
      // 聚焦tileset
      viewer.zoomTo(tileset, default_HeadingPitchRange);
      // overwrite homebutton
      viewer.homeButton.viewModel.command.beforeExecute.addEventListener(function (e) {
        e.cancel = true;
        viewer.zoomTo(tileset, default_HeadingPitchRange);
      });
    }).otherwise(function (error) {
      console.log(error);
    });
  </script>
</body>

</html>